package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.GongShi;
import com.ysd.util.DBManager;

public class GongShiDaoImpl {//实体类，起名：实体类名DaoImpl
	public GongShi getGongShi() {
		Connection conn=DBManager.getConnection();
		Statement st=null;
		ResultSet rs=null;
		GongShi company=null;
		try {
			st=conn.createStatement();
			rs=st.executeQuery("SELECT * from gongshi");
			while(rs.next()) {
				String logo=rs.getString("logo");
				String name=rs.getString("name");
				String diZhi=rs.getString("diZhi");
				String gSjieShao=rs.getString("gSjieShao");
				String dianHua=rs.getString("dianHua");
				String email=rs.getString("email");
				String gSDiZhi=rs.getString("gSDiZhi");
				String qiYeWenHua=rs.getString("qiYeWenHua");
				company=new GongShi(logo, name, diZhi, gSjieShao, dianHua, email, gSDiZhi, qiYeWenHua);
			}
			return company;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	
	public List<GongShi> getGongSi() {
		List<GongShi> gsList=new ArrayList<GongShi>();
		Connection conn=DBManager.getConnection();
		Statement st=null;
		ResultSet rs=null;
		
		try {
			st=conn.createStatement();
			rs=st.executeQuery("SELECT * from gongshi");
			while(rs.next()) {
				String logo=rs.getString("logo");
				String name=rs.getString("name");
				String diZhi=rs.getString("diZhi");
				String gSjieShao=rs.getString("gSjieShao");
				String dianHua=rs.getString("dianHua");
				String email=rs.getString("email");
				String gSDiZhi=rs.getString("gSDiZhi");
				String qiYeWenHua=rs.getString("qiYeWenHua");
				GongShi company=new GongShi(logo, name, diZhi, gSjieShao, dianHua, email, gSDiZhi, qiYeWenHua);
				gsList.add(company);
			}
			return gsList;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	
		
	
	/**
	 * 修改公司信息
	 * @param gs
	 * @return
	 */
	public int updateGongSi(GongShi gs) {
		return DBManager.executeUpdate("UPDATE gongshi set logo='"+gs.getLogo()+"',name='"+gs.getName()+"',diZhi='"+gs.getDiZhi()+"',gSjieShao='"+gs.getgSjieShao()+"',dianHua='"+gs.getDianHua()+"',email='"+gs.getEmail()+"',gSDiZhi='"+gs.getgSDiZhi()+"',qiYeWenHua='"+gs.getQiYeWenHua()+"'");
	}
}
